package com.lianbang.pharmacy.util

import cn.ubest.mvvmcore.utils.SpUtils
import com.jeremyliao.liveeventbus.LiveEventBus
import com.lianbang.pharmacy.bean.LoginBean
import com.lianbang.pharmacy.bean.UserBean
import org.litepal.LitePal

/**
 * Created by maoqi on 2020/12/28.
 */
object LoginUtils {
    var mUserBean: UserBean? = null
    var mToken: String? = null
        set(value) {
            SpUtils.putString(SpCons.TOKEN, value)
            field = value
        }
        get() {
            if (field == null) {
                field = SpUtils.getString(SpCons.TOKEN, null)
            }
            return field
        }

    fun loginSucc(userBean: UserBean) {
        mUserBean = userBean
        LiveEventBus.get("login").post(true)
    }

    fun loginOut() {
        mToken = null
        LitePal.deleteAll(LoginBean::class.java)
        LiveEventBus.get("login").post(false)
    }

    fun isLogin(): Boolean {
        return mToken?.isNotEmpty() ?: false
    }
}